package com.king.base;

import com.google.common.collect.ComparisonChain;
import com.google.common.collect.Ordering;

public class Student implements Comparable<Student> {

	public String name;

	public int age;

	public int score;
	private Integer id;

	public Student() {
	}

	public Student(String name, int age, int score) {
		this.name = name;
		this.age = age;
		this.score = score;
	}

	/**
	 * ComparisonChain是一个lazy的比较过程， 当比较结果为0的时候， 即相等的时候， 会继续比较下去， 出现非0的情况， 就会忽略后面的比较。
	 * ComparisonChain实现的compare和compareTo在代码可读性和性能上都有很大的提高。
	 * @param other
	 * @return
	 */
	@Override
	public int compareTo(Student other) {
		return ComparisonChain.start()
				.compare(name, other.name)
				.compare(age, other.age)
				.compare(score, other.score, Ordering.natural().nullsLast())
				.result();
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}
}